#include <func.h>

//验证共享堆空间

void* thread_func(void*p)
{

    printf("I am child thread, %s\n",(char*)p);
    strcpy(p,"world");//子线程修改pHead
    return NULL;
}

int main ()
{
    pthread_t th_id;
    char *pHeap=(char *)malloc(20);
    strcpy(pHeap,"hello");
    int ret=pthread_create(&th_id,NULL,thread_func,pHeap);//非void* 会自动转成void*，无需手动强转
    THREAD_ERR_CHECK(ret,"pthread_create");
   
    printf("I am main thread \n");
    pthread_join(th_id,NULL);//类似wait，用于回收子线程

    puts(pHeap);//主线程打印world
    free(pHeap);
    return 0;

}